<?php/* * 商圈API */class ApiAction extends Action {    public function index() {    	echo strtotime(date("l"));exit;    	exit;    }        //用户登录接口    public function login(){    	if(empty($_REQUEST['user_name']) || empty($_REQUEST['password'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	    	if (!preg_match("/^(13|15|18|14)[0-9]{9}$/", $_REQUEST['user_name'])) {    		$this->ajaxReturn(null, "请输入正确的手机号", -2);    	}    	$data['user_name'] = $_REQUEST['user_name'];    	$data['password'] = $_REQUEST['password'];    	$user = M('user')->field("user_id,user_name,nick_name,tel,sex,user_img")->where($data)->find();    	if($user){    	    $user['user_img'] = C('WEB_URL').$user['user_img'];    		$this->ajaxReturn($user, "登录成功", 1);    	}else{    		$this->ajaxReturn($user, "登录失败", 0);    	}    }        //用户注册接口    public function register(){    	if(empty($_REQUEST['user_name']) || empty($_REQUEST['password'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	if (!preg_match("/^(13|15|18|14)[0-9]{9}$/", $_REQUEST['user_name'])) {    		$this->ajaxReturn(null, "请输入正确的手机号", -2);    	}    	        	    	$S = M("sms");    	$mapSms['desc'] = $_REQUEST['mark'];    	$mapSms['to_phone'] = $_REQUEST['user_name'];//     	$mapSms['isused'] = 0;    	$mapSms['type'] = 1 ; //1是注册     2    重置     	     	$code = $S->field("time")->where($mapSms)->order("time desc")->limit(1)->select();    	if ($code == false) {    	    $this->ajaxReturn(null, "验证码错误", -5);    	}    	$code = $code[0]['time'];    	$S->where($mapSms)->setField("isused",1);    	if (($code + 5 * 60) < time()) {    	    $this->ajaxReturn(null, "验证码已过期，请重新获取", -4);    	}      	    	    	    	$U = M("user");    	$data['user_name'] = $_REQUEST['user_name'];    	$res = $U->where($data)->field("user_id,status") ->find();        	$rand='';    	$data['create_time'] = time();    	$data['tel'] = $_REQUEST['user_name'];    	    	//随机生成昵称 start by ming.liu    	$rand='';    	$str="爱逛街";    	for($i=0;$i<4;$i++){    	    $rand.=mt_rand(0,15);    	}    	if (isset($rand)){    	    $nickname=$str.$rand;    	}    	    	$data['nick_name'] =$nickname;    	//随机生成昵称 END  by ming.liu    	//     	$data['nick_name'] = $_REQUEST['nick_name'];    	    	     	$data['password'] = $_REQUEST['password'];    	    	$data['status'] =1;    	//     	print_r($res);    	    	if ($res) { //存在    	        	    if($res["status"]==1){ //已经启用的    	            	        $this->ajaxReturn(null, "该手机已注册，请登录。", -3);    	    }    	    else  //未启用的 启用    	    {    	            	        $user_map['user_id'] =$res["user_id"];    	            	        $res = $U ->where($user_map)->save($data);    	            	    }    	}    	    	else{    	       	    $data['user_name'] = $_REQUEST['user_name'];    	    	    	        	    $res = $U->add($data);    	    	}    	//     	for ($i=0;$i<4;$i++){//     	    $rand.=dechex(rand(0,15));//     	}    	    	if ($res) {    		$res = $U->where("user_id=$res")->find();    		$res['user_img'] = C('WEB_URL').$res['user_img'];    		$this->ajaxReturn($res, "注册成功", 1);    	} else {    		$this->ajaxReturn(null, "注册失败", 0);    	}    }        //用户忘记密码    public function reset(){        //if(empty($_REQUEST['user_name']) || empty($_REQUEST['password']) || empty($_REQUEST['mark'])){        if(empty($_REQUEST['user_name']) || empty($_REQUEST['password'])){            $this->ajaxReturn(null,'缺少参数','-1');        }             if (!preg_match("/^(13|15|18|14)[0-9]{9}$/", $_REQUEST['user_name'])) {            $this->ajaxReturn(null, "请输入正确的手机号", -2);        }                    $S = M("sms");        $mapSms['desc'] = $_REQUEST['mark'];        $mapSms['to_phone'] = $_REQUEST['user_name'];//         $mapSms['isused'] = 0;        $mapSms['type']  =2;                //1是注册     2    重置                        $code = $S->field("time")->where($mapSms)->order("time desc")->limit(1)->select();            if ($code == false) {            $this->ajaxReturn(null, "验证码错误", -5);        }        $code = $code[0]['time'];            $S->where($mapSms)->setField("isused",1);        if (($code + 5 * 60) < time()) {            $this->ajaxReturn(null, "验证码已过期，请重新获取", -4);        }                        $U = M("user");        $data['user_name'] = $_REQUEST['user_name'];        $res = $U->where($data)->getField("user_id");        $data['user_id'] = $res;        $data['password'] = $_REQUEST['password'];        $res = $U->save($data);                 if ($res) {            $this->ajaxReturn($res, "重置成功", 1);        } else {            $this->ajaxReturn(null, "重置失败", 0);        }    }            public  function  validateCode(){                        $S = M("sms");        $mapSms['desc'] = $_REQUEST['code'];        $mapSms['to_phone'] = $_REQUEST['user_name'];        $mapSms['type'] = $_REQUEST['type'];                $mapSms['isused'] = 0;                 $code = $S->field("time")->where($mapSms)->order("time desc")->limit(1)->select();                if ($code == false) {            $this->ajaxReturn(null, "验证码错误", -2);        }        $code = $code[0]['time'];                $S->where($mapSms)->setField("isused",1);        if (($code + 5 * 60) < time()) {            $this->ajaxReturn(null, "验证码已过期，请重新获取", -4);        }                                    }    //修改密码    public function editpwd(){        if(empty($_REQUEST['user_id']) || empty($_REQUEST['old_pwd']) || empty($_REQUEST['new_pwd'])){            $this->ajaxReturn(null,'缺少参数','-1');        }        $data = array();        $data['user_id'] = $_REQUEST['user_id'];        $data['password'] = $_REQUEST['old_pwd'];        $Model = M('user');        $res = $Model->where($data)->find();        if($res){            $data['password'] = $_REQUEST['new_pwd'];            $res1 = $Model->save($data);            if ($res1) {                $this->ajaxReturn($res1, "密码修改成功", 1);            } else {                $this->ajaxReturn(null, "修改失败", 0);            }        } else {            $this->ajaxReturn(null, "原密码错误", -2);        }    }            //设置昵称    public function setnick(){        if(empty($_REQUEST['user_id']) || empty($_REQUEST['nick_name'])){            $this->ajaxReturn(null,'缺少参数','-1');        }        $Model = M('user');        $map['user_id'] = array('neq',$_REQUEST['user_id']);        $map['nick_name'] = $_REQUEST['nick_name'];        $r = $Model->where($map)->find();        if($r){            $this->ajaxReturn(null, "来的太晚,昵称已被抢注了哦", -2);        }            $data = array();        $data['user_id'] = $_REQUEST['user_id'];        $data['nick_name'] = $_REQUEST['nick_name'];        $res = $Model->save($data);        if ($res) {            $this->ajaxReturn($data, "修改成功", 1);        } else {            $this->ajaxReturn(null, "修改失败", 0);        }    }        public function uploadUserImg(){        if(empty($_REQUEST['user_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }                        $data = array();                    $path = "upload/" . date("Ymd") . "/";        if (!is_dir($path)) {            mkdir($path);        }                 if (!empty($_FILES)){            $file =(array)uploadFile(null,null,$path);            for ($i = 0; $i < count($file); $i++) {                $img[] = $path .$file[$i]['savename'];                            }                        $ids ='';            	            foreach ($img as $val){                $ids .= $val.',';            }            $ids = substr($ids,0,strlen($ids)-1);            	            $data['user_img'] =$ids;            //             $data['user_img'] = json_encode($img);            //     	    print_r($img);        }                //         if (!empty($_FILES)) {//             $file =(array)uploadFile();//             for ($i = 0; $i < count($file); $i++) {//                 $data['user_img'] = $file[$i]['savepath'].$file[$i]['savename'];//             }//         }else{//             $this->ajaxReturn(null,'缺少参数','-1');//         }        $data['user_id'] = $_REQUEST['user_id'];        $res = M("user")->save($data);        if($res){            $data['user_img'] = C('WEB_URL').$data['user_img'];            $this->ajaxReturn($data,'修改成功',1);        }        $this->ajaxReturn(null,'修改失败',0);    }        //商圈列表    public function businessCircleList(){    	$list = M('circle')->field("circle_id,circle_name")->select();    	$this->ajaxReturn($list, "查询成功", 1);    }                //商场列表    public function marketList(){    	$page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];    	$num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];    	     	//按距离排行    	    	    	$map = array();		if($_REQUEST['circle_id']){			$map['circle_id'] = $_REQUEST['circle_id'];		}		if($_REQUEST['keyword']){		    $map['market_name'] = array('like','%'.$_REQUEST['keyword'].'%');		}		//经纬度						$lat = $_REQUEST['lat'];		$lng = $_REQUEST['lng'];						// 		foreach($market_list as $key=>$val){// 		    $market_list[$key]['juli'] = getDistance($lat,$lng,$val['lat'],$val['lng']);// 		}				if($lat != '' && $lng !=''){		    $order = ' ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS(('.$lng.'* 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6380 asc';		    		    $list = M('market')->where($map)->order($order)->limit(($page-1)*$num, $num)->select();		}		else{    			    $list = M('market')->where($map)->limit(($page-1)*$num, $num)->select();		}    	for($i=0;$i<count($list);$i++){    	        		$list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];    		$list[$i]['big_logo'] = C('WEB_URL').$list[$i]['big_logo'];    		if($lat&&$lng)    		$list[$i]['juli'] = $this->getDistance($lat,$lng,$list[$i]['lat'],$list[$i]['lng']);    		else     		    $list[$i]['juli'] =-1;    		    		    	}    	    	if($lat&&$lng){        	    usort($list, function($a, $b){    	    $al = $a['juli'];    	    $bl = $b['juli'];    	    if ($al == $bl)    	        return 0;    	    return ($al > $bl) ? +1 : -1;    	});    	    	}    	$this->ajaxReturn($list, "查询成功", 1);    }            /**     * @desc 根据两点间的经纬度计算距离     * @param float $lat 纬度值     * @param float $lng 经度值     */    private  function getDistance($lat1, $lng1, $lat2, $lng2)    {        $earthRadius = 6367000; //approximate radius of earth in meters            /*         Convert these degrees to radians         to work with the formula         */            $lat1 = ($lat1 * pi() ) / 180;        $lng1 = ($lng1 * pi() ) / 180;            $lat2 = ($lat2 * pi() ) / 180;        $lng2 = ($lng2 * pi() ) / 180;            /*         Using the         Haversine formula         http://en.wikipedia.org/wiki/Haversine_formula         calculate the distance         */            $calcLongitude = $lng2 - $lng1;        $calcLatitude = $lat2 - $lat1;        $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);        $stepTwo = 2 * asin(min(1, sqrt($stepOne)));        $calculatedDistance = $earthRadius * $stepTwo;            return round($calculatedDistance);    }        //好友足迹的商家列表    public function businessList_F(){                //使用f_id 代替 user_id        if(empty($_REQUEST['f_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }                        $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];                $map['o.user_id'] =$_REQUEST['f_id'];                $map_f['o.status'] =3;                        $Li = M('business');                $list =$Li                 ->join('right join sq_order o on o.business_id=sq_business.business_id ')                        ->field(array("sq_business.business_id,sq_business.business_name,0 as is_keep ,1 as is_come, 0  as  is_yh,  concat(\"".C('WEB_URL').'/Home/info/index/id/'."\") as url, market_id,market_name,letter,address,sq_business.tel,open_time,floor,service,sq_business.des,sq_business.status,if(sq_business.lng,sq_business.lng ,0) as lng, if(sq_business.lat,sq_business.lat ,0) as lat, admin_business_id,concat(\"".C('WEB_URL')."\",small_logo) as small_logo, concat(\"".C('WEB_URL')."\",big_logo) as big_logo "))                 ->where($map)                ->order(' sq_business.business_id desc')                ->limit(($page-1)*$num, $num)->select();                $data['list'] = $list;        $this->ajaxReturn($data, "查询成功", 1);                    }           //商家列表    public function businessList(){                        $data =  array();        $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];        $map = array();                if($_REQUEST['keyword']){            $map['business_name'] = array('like','%'.$_REQUEST['keyword'].'%');        }        if($_REQUEST['floor']){            $map['floor'] = $_REQUEST['floor'];        }        $data['floor'] = null;        if($_REQUEST['market_id']){                        $map['market_id'] = $_REQUEST['market_id'];                            $maps = array();            $maps['market_id'] = $_REQUEST['market_id'];            $floors = M('floor')->field("floor_name as floor,floor_img")->where($maps)->select();            if($floors){                for($i=0;$i<count($floors);$i++){                    $floors[$i]['floor_img'] = C('WEB_URL').$floors[$i]['floor_img'];                }                $data['floor'] = $floors;            }        }elseif($_REQUEST['circle_id']){            $map1['circle_id'] = $_REQUEST['circle_id'];            $mlist = M("market")->field("market_id")->where($map1)->select();            $ids = '';                                    foreach ($mlist as $val){                $ids .= $val['market_id'].',';            }                        $ids .=" 0,";            $ids = substr($ids,0,strlen($ids)-1);            $map['market_id'] = array('in',$ids);                        $map['circle_id'] = $_REQUEST['circle_id'];            $map['status'] ='2';                    }                        $Li = M('business');                 if($_REQUEST['user_id']){                $user_id=$_REQUEST['user_id'];                             //	1.商家   2.卡券 拼接user_id            // $map['_string'] = "  k.user_id IS NULL or ( k.user_id=".$user_id."  ) ";                            $list =$Li                         //->join('sq_keep_b k on k.x_id=sq_business.business_id ')                                    // IF(k.user_id=".$user_id.",IF(k.type=1,'1','0'),'0') as is_keep  ,                        ->field(array("business_id,business_name,1 as is_come, 0  as  is_yh, concat(\"".C('WEB_URL').'/Home/info/index/id/'."\",business_id) as url,  market_id,market_name,letter,address,tel,open_time,floor,service,des,sq_business.status,if(sq_business.lng,sq_business.lng ,0) as lng, if(sq_business.lat,sq_business.lat ,0) as lat,admin_business_id,concat(\"".C('WEB_URL')."\",small_logo) as small_logo, concat(\"".C('WEB_URL')."\",big_logo) as big_logo "))                         ->where($map)                        ->order(' business_id desc')                        ->limit(($page-1)*$num, $num)->select();                     }        else{            	            	            //     	    0 as is_keep , \"复兴中路529号\" as address,            	//             $list = $Li->where($map)->limit(($page-1)*$num, $num)->select();            	            $list =$Li                           ->field(array("business_id,business_name,0 as is_keep ,1 as is_come, 0  as  is_yh,  concat(\"".C('WEB_URL').'/Home/info/index/id/'."\",business_id) as url, market_id,market_name,letter,address,tel,open_time,floor,service,des,sq_business.status,if(sq_business.lng,sq_business.lng ,0) as lng, if(sq_business.lat,sq_business.lat ,0) as lat,admin_business_id,concat(\"".C('WEB_URL')."\",small_logo) as small_logo, concat(\"".C('WEB_URL')."\",big_logo) as big_logo "))            	            ->where($map)                        ->order(' business_id desc')                        ->limit(($page-1)*$num, $num)->select();                	                                }                                //sq_order_num-->order_id     where -->$list['business_id']  and frind_id ==use_id        //         $zuji[0]['user_id'] = 1;//         $zuji[0]['user_name'] = '徜徉';//         $zuji[0]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';//         $zuji[1]['user_id'] = 12;//         $zuji[1]['user_name'] = '还开心';//         $zuji[1]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1563418937,2640257337&fm=111&gp=0.jpg';//         $zuji[2]['user_id'] = 12;//         $zuji[2]['user_name'] = '大风歌';//         $zuji[2]['user_img'] = 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1158549394,2821559545&fm=111&gp=0.jpg';//之前的阿飞测试数据 已经去掉                    // $f_map['user_id'] =$_REQUEST['user_id'];           //如果含有user_id 查询 好友足迹                            $map_f['sq_friend.user_id'] =$_REQUEST['user_id'];            //             unset( $map['market_id']);            if($_REQUEST['user_id']){                for($i=0;$i<count($list);$i++){                      //                 	    $list[$i]['url'] = C('WEB_URL').'/Home/info/index/id/'.$list[$i]['business_id'];        //                 		$list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];        //                 		$list[$i]['big_logo'] = C('WEB_URL').$list[$i]['big_logo'];        //                 		$list[$i]['is_keep'] = 0;        //                 		$list[$i]['is_yh'] = 0;        //                 		$list[$i]['is_come'] = 1;                                $map_f['o.business_id'] =$list[$i]['business_id'];             //           1.未支付  2.已支付未消费   3.已消费  4.已过期                                    $map_f['o.status'] =3;                        //            之前的阿飞测试数据 已经去掉                                                $F = M('friend')                                                 ->join("right join  sq_order o on  o.user_id  = sq_friend.f_user_id ")                                                 ->join(' sq_user u on  u.user_id = sq_friend.f_user_id ')                                                 ->field(array("u.nick_name as nick_name  ,u.user_id as user_id ,concat(\"".C('WEB_URL')."\",u.user_img) as user_img "))                                                ->where($map_f)->select();                                                if($F){                                                    $list[$i]['zuji'] = $F;                        }                                                                        //是否收藏  is_keep                                                                        $data['user_id'] = $_REQUEST['user_id'];                        $data['x_id'] =$list[$i]['business_id'];//                         $data['type'] = 1;                                                $res = M('keep_b')->where($data)->find();                                                                        if($res){                                                        $list[$i]['is_keep'] =1 ;                                                                                }                                                else{                                                        $list[$i]['is_keep'] =0 ;                                                    }                                        //                         else{                            //                            // $list[$i]['zuji'] ="NULL";//                         }                    }                              }                $data['list'] = $list;        if($list)          $this->ajaxReturn($data, "查询成功", 1);        else         $this->ajaxReturn($data, "数据为空", 0);    }        //     public function businessList_2(){//     	$data =  array();//     	$page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];//     	$num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];//     	$map = array();//     	if($_REQUEST['keyword']){//     	    $map['business_name'] = array('like','%'.$_REQUEST['keyword'].'%');//     	}//     	if($_REQUEST['floor']){//     	    $map['floor'] = $_REQUEST['floor'];//     	}//     	$data['floor'] = null;//     	if($_REQUEST['market_id']){//     		$map['market_id'] = $_REQUEST['market_id'];    		//     		$maps = array();//     		$maps['market_id'] = $_REQUEST['market_id'];//     		$floors = M('floor')->field("floor_name as floor,floor_img")->where($maps)->select();//     		if($floors){//     		    for($i=0;$i<count($floors);$i++){//     		        $floors[$i]['floor_img'] = C('WEB_URL').$floors[$i]['floor_img'];//     		    }//     		    $data['floor'] = $floors;//     		}//     	}elseif($_REQUEST['circle_id']){//     	    $map1['circle_id'] = $_REQUEST['circle_id'];//     	    $mlist = M("market")->field("market_id")->where($map1)->select();//     	    $ids = '';//     		foreach ($mlist as $val){//     		    $ids .= $val['market_id'].',';//     		}//     		$ids = substr($ids,0,strlen($ids)-1);//     		$map['market_id'] = array('in',$ids);//     	}//     	$Li = M('business');//     	$list = $Li->where($map)->limit(($page-1)*$num, $num)->select();    	//     	$zuji[0]['user_id'] = 1;//     	$zuji[0]['user_name'] = '徜徉';//     	$zuji[0]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';//     	$zuji[1]['user_id'] = 12;//     	$zuji[1]['user_name'] = '还开心';//     	$zuji[1]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1563418937,2640257337&fm=111&gp=0.jpg';//     	$zuji[2]['user_id'] = 12;//     	$zuji[2]['user_name'] = '大风歌';//     	$zuji[2]['user_img'] = 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1158549394,2821559545&fm=111&gp=0.jpg';    	    	//     	for($i=0;$i<count($list);$i++){//     	    $list[$i]['url'] = C('WEB_URL').'/Home/info/index/id/'.$list[$i]['business_id'];//     		$list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];//     		$list[$i]['big_logo'] = C('WEB_URL').$list[$i]['big_logo'];//     		$list[$i]['is_keep'] = 0;//     		$list[$i]['is_yh'] = 0;//     		$list[$i]['is_come'] = 1;//     		$list[$i]['zuji'] = $zuji;//     	}//     	$data['list'] = $list;//     	$this->ajaxReturn($data, "查询成功", 1);//     }        //商家详情    public function businessInfo(){    	if(empty($_REQUEST['business_id'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	    	$info = M('business')->find($_REQUEST['business_id']);    	//     	$info['is_Attend'] = 1;//     	$info['is_keep'] = 1;//     	$info['is_yh'] = 1;//     	$info['is_come'] = 1;    	$info['url'] = C('WEB_URL').'/Home/info/index/id/'.$_REQUEST['business_id'];    	    	$info['share_url'] = C('WEB_URL').'/Home/info/index/id/'.$_REQUEST['business_id'];    	     	$info['small_logo'] = C('WEB_URL').$info['small_logo'];    	$info['big_logo'] = C('WEB_URL').$info['big_logo'];    	     	    	    	    	    	    	    	$c_map ['b.business_id'] = $_REQUEST['business_id'];    	    	$list = M('coupon')    	    	    	->join (' sq_business b on   sq_coupon.business_id=b.business_id ')    		    		    	->field(array("coupon_id, 0 as is_keep , b.address as address, coupon_name,b.business_id,b.business_name,start_use_time,end_use_time,concat(\"".C('WEB_URL')."\",sq_coupon.small_logo) as small_logo,tishi,sq_coupon.des,old_price,new_price"))    	     	    	->where($c_map)->order(' coupon_id desc ')    	    	->limit(3)->select();    	     	unset($c_map ['b.business_id']);    	    	$c_map ['business_id'] = $_REQUEST['business_id'];    	     	    	//体验卡券的数据    	    	$info['coupon_count']=10;    	    	    	    	$info['coupon_List']=$list;    	    	    	$commet_list= M('comment')    	    	->field("comment_id,user_id,coupon_id,content, concat(\"".C('WEB_URL')."\",img) as img ,time,status,type,business_id,score")    	    	->where($c_map)->	order(' comment_id desc')    	    	->limit(3)->select();    	   // 1好评2中评3差评    	    	$info['commet_list']=$commet_list;    	//评论的数量与好评率    	     	$info['commet_count']=count($commet_list);    	    	$info['commet_rate']=0.8;    	    	if($_REQUEST['user_id']){    	     	    	        //                 	    $list[$i]['url'] = C('WEB_URL').'/Home/info/index/id/'.$list[$i]['business_id'];    	        //                 		$list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];    	        //                 		$list[$i]['big_logo'] = C('WEB_URL').$list[$i]['big_logo'];    	        //                 		$list[$i]['is_keep'] = 0;    	        //                 		$list[$i]['is_yh'] = 0;    	        //                 		$list[$i]['is_come'] = 1;    	    	        $map_f['sq_friend.user_id'] =$_REQUEST['user_id'];    	        	        $map_f['o.business_id'] =$_REQUEST['business_id'];    	        //           1.未支付  2.已支付未消费   3.已消费  4.已过期    	        $map_f['o.status'] =3;    	    	        //            之前的阿飞测试数据 已经去掉    	    	        $F = M('friend')    	             	        ->join("right join  sq_order o on  o.user_id  = sq_friend.f_user_id ")    	             	        ->join(' sq_user u on  u.user_id = sq_friend.f_user_id ')    	             	        ->field(array("u.nick_name as nick_name  ,u.user_id as user_id ,concat(\"".C('WEB_URL')."\",u.user_img) as user_img "))    	    	        ->where($map_f)->select();    	    	        if($F){    	    	            $info['zuji'] = $F;    	        }    	    	}    	            	//     	for($i=0;$i<count($list);$i++){//     	    $list[$i]['user_img'] = C('WEB_URL').$list[$i]['user_img'];//     	    $list[$i]['img'][0] = C('WEB_URL')."Public/default/show.jpg";//     	}    	    	if($info){    		$this->ajaxReturn($info, "查询成功", 1);    	}else{    		$this->ajaxReturn(null, "查询失败", 0);    	}    }        //用户收藏商家    public function keepBusiness(){    	if(empty($_REQUEST['business_id']) || empty($_REQUEST['user_id'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	    	$data =  array();    	$data['user_id'] = $_REQUEST['user_id'];    	$data['x_id'] = $_REQUEST['business_id'];    	$data['type'] = 1;    	$res = M('keep_b')->where($data)->find();    	if($res){    	    $res = M("keep_b")->where("keep_id=".$res['keep_id'])->delete();    	    $this->ajaxReturn(null,"取消收藏成功",2);    	}else{    		$res = M('keep_b')->add($data);    		$this->ajaxReturn(null,"收藏成功",1);    	}    }        //用户收藏卡卷    public function keepCoupon(){        if(empty($_REQUEST['coupon_id']) || empty($_REQUEST['user_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }                 $data =  array();        $data['user_id'] = $_REQUEST['user_id'];        $data['x_id'] = $_REQUEST['coupon_id'];        $data['type'] = 2;        $res = M('keep')->where($data)->find();        if($res){            $res = M("keep")->where("keep_id=".$res['keep_id'])->delete();            $this->ajaxReturn(null,"取消收藏成功",2);        }else{            $res = M('keep')->add($data);            $this->ajaxReturn(null,"收藏成功",1);        }    }        //用户收藏    public function mykeep(){        //         $info = '测试信息';//         trace($info,'提示');                if(empty($_REQUEST['type']) || empty($_REQUEST['user_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }            $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];        $map["user_id"] = $_REQUEST['user_id'];        if($_REQUEST['type'] == 1){                        $Model = M("keep_b");            $map["type"] = $_REQUEST['type'];              $list = $Model->join("sq_business b on sq_keep_b.x_id=b.business_id")->field("business_id,business_name,small_logo,big_logo,address,tel,open_time,sq_keep_b.user_id")->where($map)->limit(($page-1)*$num, $num)->select();               }elseif($_REQUEST['type'] == 2){                        $Model = M("keep");            $map["sq_keep.type"] = $_REQUEST['type'];            $list = $Model->join("sq_coupon c on sq_keep.x_id=c.coupon_id")->field("coupon_id,coupon_name,business_id,business_name,start_use_time,small_logo,sq_keep.user_id")->where($map)->limit(($page-1)*$num, $num)->select();        }        if($list){            for($i=0;$i<count($list);$i++){                $list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];                if($list[$i]['big_logo']){                    $list[$i]['big_logo'] = C('WEB_URL').$list[$i]['big_logo'];                }            }            $this->ajaxReturn($list,"查询成功",1);        }        $this->ajaxReturn(null,"查询成功",1);    }            //用户卡券    public function mycoupon(){        if(empty($_REQUEST['user_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }            $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];                $map = array();                        //1.未支付  2.已支付未消费   3.已消费  4.已过期        if($_REQUEST['type'] == 1){                        $map["sq_order.status"] = 1;                    }elseif($_REQUEST['type'] == 2)        {            $map["sq_order.status"] = 2;        }                elseif($_REQUEST['type'] == 3){            $map["sq_order.status"] = 3;        }                elseif($_REQUEST['type'] == 4){            $map["sq_order.status"] = 4;        }                        $map ["sq_order.user_id"] =$_REQUEST['user_id'];                        $Model = M("order");                $list = $Model->join("  sq_coupon c on sq_order.coupon_id=c.coupon_id")        ->field("c.coupon_id,c.coupon_name,c.business_id,c.business_name,c.start_use_time,c.end_use_time,c.small_logo,sq_order.order_id,sq_order.user_id,sq_order.user_name,sq_order.count,sq_order.price,sq_order.total,sq_order.time,sq_order.status,sq_order.num,sq_order.pay_type")        ->where($map)        ->order(' sq_order.time desc ')        ->limit(($page-1)*$num, $num)->select();                                     $Model_num=M('order_num');                        if($list){            for($i=0;$i<count($list);$i++){                                $list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];                                $num_map['order_id'] =$list[$i]['order_id'];                                                                                $list[$i]['nums'] =$Model_num                ->join("sq_comment c on sq_order_num.num_id=c.coupon_id")                ->field("sq_order_num.num_id ,sq_order_num.number ,if(sq_order_num.status=3,'1','0') as is_use ,if(c.coupon_id,'1','0') as is_comment ")                ->where($num_map)->select();                                                if(empty(  $list[$i]['nums'] )){                                                            $nums = explode(',',$list[$i]['num']);                    for ($j=0;$j<count($nums);$j++){                                            $list[$i]['nums'][$j]['number'] = $nums[$j];                        $list[$i]['nums'][$j]['num_id'] = 1;                        //此卡券是否使用 1 使用过 0未使用                        $list[$i]['nums'][$j]['is_use'] = 0;                        //是否被评价过                        $list[$i]['nums'][$j]['is_comment'] = 0;                                        }                                    }                         //                 if($list[$i]['count']==1){//                     //order_id                    //                 }else{                                        //修改为外表关联字段                                    /*                     $nums = explode(',',$list[$i]['num']);                                        for ($j=0;$j<count($nums);$j++){                                                $list[$i]['nums'][$j]['number'] = $nums[$j];                        $list[$i]['nums'][$j]['num_id'] = 1;                        //此卡券是否使用 1 使用过 0未使用                        $list[$i]['nums'][$j]['is_use'] = 0;                        //是否被评价过                        $list[$i]['nums'][$j]['is_comment'] = 1;                                            }            */                //根据多少张 返回多个                           }        }                                $this->ajaxReturn($list,"查询成功",1);    }        //用户下单购买体验卡券    public function buy(){    	if(empty($_REQUEST['phone'])||empty($_REQUEST['coupon_id'])||empty($_REQUEST['user_id'])||empty($_REQUEST['count'])||empty($_REQUEST['pay_type'])||empty($_REQUEST['phone'])||empty($_REQUEST['is_noname'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	    	    	    	$data =  array();    	$data['order_id'] = time().rand(100,999);    	$data['coupon_id'] = $_REQUEST['coupon_id'];//     	$data['coupon_id'] = $_REQUEST['coupon_id'];    	$data['user_id'] = $_REQUEST['user_id'];    	$data['count'] = $_REQUEST['count'];    	$data['pay_type'] = $_REQUEST['pay_type'];    	$data['status'] ='1';    	     	$data['is_noname'] = $_REQUEST['is_noname']; //是否匿名购买    	$data['time'] = time();    	    	//生成随机码    	$nums = '';    	for($i=0;$i<$data['count'];$i++){    	    $nums .= rand(10000000,99999999).',';    	}    	$nums = substr($nums,0,strlen($nums)-1);    	$data['num'] = $nums;    	    	$info = M("user")->field("user_name,user_img")->find($_REQUEST['user_id']);    	$data['user_name'] = $info['user_name'];    	$data['user_img'] = $info['user_img'];    	    	$cinfo = M("coupon")->field("coupon_id,new_price,business_id,business_name")->find($_REQUEST['coupon_id']);    	$data['price'] = $cinfo['new_price'];    	$data['total'] = $cinfo['new_price']*$_REQUEST['count'];    	    	$data['business_id'] =$cinfo ['business_id'];    	    	$data['business_name'] =$cinfo ['business_name'];    	    	if($_REQUEST['phone'])    	$data['tel'] = $_REQUEST['phone'];    	    	    	    	    	$res = M('order')->add($data);    	    	    	$num = explode(',',$nums);    	    	    	    	//卡券购买 生成验证码    	for ($j=0;$j<count($num);$j++){    	        	    $num_data['order_id']=$data['order_id'];    	    	    	        	    $num_data['number']=$num[$j];    	    $num_data['time'] =$data['time'] ;    	    $num_data['status']='2';    	    $res_num = M("order_num")->add($num_data);    	    	    	}    	    	$data_number ="您好，您购买的卡券的商户验证码为:" . $nums ."！";    	$res=$this->send($_REQUEST['phone'],$data_number);    	    	$res=1;    	//发送验证短信    	if($res){    		$this->ajaxReturn($data['order_id'],"下单成功",1);    		    	    	}else{    		$this->ajaxReturn(null,"下单失败",0);    	}    	    	    }        //用户发表体验报告(评论)    public function comment(){    	if(empty($_REQUEST['num_id'])||empty($_REQUEST['user_id'])||empty($_REQUEST['content'])||empty($_REQUEST['score'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	//coupon_id 已经废弃掉  num_id    	$coupon = M("coupon")->field("business_id")->where("coupon_id=".$_REQUEST['num_id'])->find();    	    	$data =  array();    	    	$data['business_id'] = $coupon['business_id'];    	//     	$data['coupon_id'] = $_REQUEST['coupon_id'];    	    	$data['coupon_id'] = $_REQUEST['num_id'];    	     	    	$data['user_id'] = $_REQUEST['user_id'];    	$data['content'] = $_REQUEST['content'];    	$data['score'] = $_REQUEST['score'];    	$data['time'] = time();    	    	$path = "upload/" . date("Ymd") . "/";    	if (!is_dir($path)) {    	    mkdir($path);    	}    	    	if (!empty($_FILES)){    	    $file =(array)uploadFile(null,null,$path);    	    for ($i = 0; $i < count($file); $i++) {    	            $img[] = $path .$file[$i]['savename'];    	    }    	        	    $ids ='';    	    	    	    foreach ($img as $val){    	        $ids .= $val.',';    	    }    	    $ids = substr($ids,0,strlen($ids)-1);    	    	    	    $data['img'] =$ids;    	          	}      	    	$datas['desc'] = json_encode($_FILES);      	M("test")->add($datas);    	    	$res = M('comment')->add($data);        if($res){    		$this->ajaxReturn($res,"评论成功",1);    	}else{    		$this->ajaxReturn(null,"评论失败",0);    	}    }        //获取体验卡券列表(评论列表)    public function commentList(){//         if(empty($_REQUEST['business_id'])){//             $this->ajaxReturn(null,'缺少参数','-1');//         }                                $type= $_REQUEST['type'];                        $Model = M('comment');                                $coupon_id=$_REQUEST['coupon_id'];                        //         1好评2中评3差评                if($_REQUEST['coupon_id']){                  //$coupon_id 转化成 num  的  num_id                        $map_order['coupon_id']=$coupon_id;                        //order            $num_l = M('order')                        ->join("right join sq_order_num n on n.order_id=sq_order.order_id")                                    ->field("num_id")->where($map_order)->select();                                    $ids = '';            foreach ($num_l as $val){                                                                $ids .= $val['num_id'].',';                                             }                                                         $ids = substr($ids,0,strlen($ids)-1);                                           $map['sq_comment.coupon_id'] = array('in',$ids);                        if(empty($ids)){                                $this->ajaxReturn(null,"没有数据！",0);                            }                //             $map["sq_comment.coupon_id"] =$_REQUEST['coupon_id'];                                                        if($type>0){                              $map["sq_comment.type"] =$type;                                 $res = $Model->query("SELECT type, sum(score) as score,count(comment_id) as count from sq_comment WHERE  type=$type and   coupon_id in ($ids) group by type order   by  type   ");                            }                else{                       $res = $Model->query("SELECT type,sum(score) as score,count(comment_id) as count from sq_comment WHERE  coupon_id in ($ids) group by type order   by  type ");                            }                                }                if(($_REQUEST['business_id'])){                        $map["sq_comment.business_id"] =$_REQUEST['business_id'];                                     if($type>0){                                  $map["sq_comment.type"] =$type;                                     $res = $Model->query("SELECT type,sum(score) as score,count(comment_id) as count from sq_comment WHERE  type=$type and  business_id=".$_REQUEST['business_id'] ." group by type order   by  type ");             }               else{                                         $res = $Model->query("SELECT type,sum(score) as score,count(comment_id) as count from sq_comment WHERE business_id=".$_REQUEST['business_id'] ." group by type order   by  type ");               }                    }        //type // 1全部 2好评 3中评 4差评                $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];        //$map['sq_comment.business_id'] = $_REQUEST['business_id'];                $data = array();                          //         if($res[0]['count']){        //             $bai = round(($res[0]['score']/(5*$res[0]['count']))*100)."%";        //             $data['scoreInfo'] = $res[0];        //             $data['scoreInfo']["percent"] = $bai;        //         }                                if($type==0){                                    $sum_count=0;                        $sum_score=0;                        //第一次赋数值            $scoreInfo[0]['type']=0;                        $scoreInfo[0]['count']=$sum_count;                        $scoreInfo[0]['score']=$sum_score;                                        for($i=0;$i<count($res);$i++){                                                                         $scoreInfo[$i+1]=$res[$i];                                        $sum_count=$sum_count+$res[$i]['count'];                                        $sum_score=$sum_score+$res[$i]['score'];                }                                //第二次赋数值                                                $scoreInfo[0]['type']=0;                                $scoreInfo[0]['count']=$sum_count;                                $scoreInfo[0]['score']=$sum_score;                                        }        else{                        $scoreInfo =$res;                                }                $data['scoreInfo'] = $scoreInfo;                        $list = $Model->join("sq_user u on sq_comment.user_id=u.user_id")->field("sq_comment.*,u.user_name,u.nick_name,u.user_img")->where($map)->limit(($page-1)*$num, $num)->select();                for($i=0;$i<count($list);$i++){                                  $list[$i]['user_img'] = C('WEB_URL').$list[$i]['user_img'];                        if(empty($list[$i]['lng']))                $list[$i]['lng']=0;                       if(empty($list[$i]['lat']))                $list[$i]['lat']=0;                        $img_ = explode(',',$list[$i]['img']);                        $img_s='';                        for ($j=0;$j<count($img_);$j++){                 $img_s=$img_s. C('WEB_URL').$img_[$j].",";                        }                        $list[$i]['img']=$img_s;        }        if($list){            $data['list'] = $list;            $this->ajaxReturn($data,"查询成功",1);        }else{            $this->ajaxReturn(null,"没有数据",0);        }    }        //获取卡券列表    public function couponList(){        //从这个开始 is_keep 主 外键 关联       	$page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];    	$num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];    	$map = array();//     	if($_REQUEST['circle_id']){//     		$map['circle_id'] = $_REQUEST['circle_id'];//     		$map['coupon_type']=1;    		//     	}    	    	//  //所属类型  1.商家  2.活动    	    	    	//     	1.商家   2.卡券    	    	$tc_ype=2;    	//     	$tc_ype=1;    	    	if($_REQUEST['business_id']){    	        		$map['sq_coupon.business_id'] = $_REQUEST['business_id'];    		    	    	//     		$map['coupon_type']=1;   	    	}    	if($_REQUEST['service_id']){    	        	    $map['sq_coupon.service_id'] = $_REQUEST['service_id'];  //     	    $map['coupon_type']=2;    	        	    	    	}    	    	    	if($_REQUEST['user_id']){    	        	    $user_id=$_REQUEST['user_id'];    	        	    //    	    	  //  $map['_string'] = "  k.user_id IS NULL or ( k.user_id=".$user_id."  ) ";    	    //     	    sq_coupon_type t on   sq_coupon.business_id=t.business_i    	        	        	    // IF(k.user_id=".$user_id.",IF(k.type=2,'1','0'),'0') as is_keep ,     	    $list = M('coupon')    	        	    ->join (' sq_business b on   sq_coupon.business_id=b.business_id ')    	    //      	    ->join('sq_keep k on k.x_id=sq_coupon.coupon_id ')     	        	    ->field(array("if(b.lng,b.lng ,0), b.lat, coupon_id, b.address as address, coupon_name,sq_coupon.business_id,b.business_name,start_use_time,end_use_time,concat(\"".C('WEB_URL')."\",sq_coupon.small_logo) as small_logo,tishi,sq_coupon.des,old_price,new_price"))    	        	    ->where($map)    	        	    ->limit(($page-1)*$num, $num)    	        	    ->select();    	        	    for($i=0;$i<count($list);$i++){    	                	        	           $data['user_id'] = $_REQUEST['user_id'];            	                	    $data['x_id'] =$list[$i]['coupon_id'];            	                	    //                         $data['type'] = 2;            	    	            	    $res = M('keep')->where($data)->find();            	                	    if($res){            	                	        $list[$i]['is_keep'] =1 ;            	                	                	    }            	                	    else{            	                	        $list[$i]['is_keep'] =0 ;            	                	    }    	        	    }    	        	    	    	}    	    	else {    	        	    $list = M('coupon')    	        	    ->join (' sq_business b on   sq_coupon.business_id=b.business_id ')    	        	    ->field(array(" if(b.lng,b.lng ,0) as lng, if(b.lat,b.lat ,0) as lat, coupon_id, 0 as is_keep , b.address as address, coupon_name,b.business_id,b.business_name,start_use_time,end_use_time,concat(\"".C('WEB_URL')."\",sq_coupon.small_logo) as small_logo,tishi,sq_coupon.des,old_price,new_price"))    	        	    ->where($map)->order(' coupon_id desc')->limit(($page-1)*$num, $num)->select();    	    	    	        	       	        	}   //sq_keep 	    	    	    	if($list){    		$this->ajaxReturn($list,"成功",1);    	}else{    		$this->ajaxReturn(null,"没有数据",0);    	}    }            public function test(){        echo "111";                    }    //获取卡券列表 ticketsList 获取门票接口 coupon_type  所属类型  1.商家  2.活动         //获取门票接口    public function ticketsList(){        //         service_id//         $map = array();                if(empty($_REQUEST['service_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }                       $map['status']=1;                    $map['coupon_type']=2;    //所属类型  1.商家  2.活动                            $data = array();                            $data = M('service')->field("service_name,address,img")->where($map)->find();            //             print_r($data);            //             exit;                                    $map['business_id']= $_REQUEST['service_id'];                        $data['img'] =  C('WEB_URL').$data['img'] ;                                            $list = M('coupon_type')->field("c_id,coupon_type,c_type,mark,start_time,end_time")->where($map)->select();                                        for($i=0;$i<count($list);$i++){                                     $coupons_map['coupon_type_id']=$list[$i]['c_id'];                        //             $coupons = M('coupon')->where($coupons_map)->select();            //                        $coupons = M('coupon')->field(" coupon_id,old_price, new_price ")->where($coupons_map)->select();                        $list[$i]['coupons']=$coupons;            //             $list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];//             $list[$i]['is_keep'] = 0;//             $list[$i]['address'] = "复兴中路529号";        }                        $data["tickets"]=$list;                        if($list){            $this->ajaxReturn($data,"成功",1);        }else{            $this->ajaxReturn(null,"没有数据",0);        }    }            //获取卡券列表    public function guessLike(){        /* if(empty($_REQUEST['user_id'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	} */        $map = array();        /* if($_REQUEST['circle_id']){            $map['circle_id'] = $_REQUEST['circle_id'];        } */        $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 4 : $_REQUEST['page_line'];        $list = M('coupon')->field("coupon_id,coupon_name,small_logo")->where($map)->limit(($page-1)*$num, $num)->select();        for($i=0;$i<count($list);$i++){            $list[$i]['small_logo'] = C('WEB_URL').$list[$i]['small_logo'];        }        if($list){            $this->ajaxReturn($list,"成功",1);        }else{            $this->ajaxReturn(null,"没有数据",0);        }    }        //商家地址处理    /*    public function addressdata(){        $B = M('business');        $map['market_id'] = 0;        $map['circle_id'] = 1;        $list = $B->field("business_id,address")->where($map)->select();        for($i=0;$i<count($list);$i++){            $data = array();            $data['business_id'] = $list[$i]['business_id'];            $data['address'] = $list[$i]['address'].'号';            $B->save($data);        }    }        //商场图片处理    public function mimgdata(){        $B = M('market');        $list = $B->select();        for($i=0;$i<count($list);$i++){            $data = array();            $data['market_id'] = $list[$i]['market_id'];            $data['small_logo'] = 'upload/market_img/'.$list[$i]['letter'].'/'.$list[$i]['letter'].'_logo.jpg';            $data['big_logo'] = 'upload/market_img/'.$list[$i]['letter'].'/'.$list[$i]['letter'].'.jpg';            $B->save($data);        }    }           //商家图片处理    public function bimgdata(){        $B = M('business');        $list = $B->where("business_id>1750")->select();        for($i=0;$i<count($list);$i++){            $data = array();            $data['business_id'] = $list[$i]['business_id'];            $letter = substr($list[$i]['letter'],0,strlen($list[$i]['letter'])-1);            if($list['small_logo'] != 'Public/default/logo.jpg'){                $data['small_logo'] = 'upload/business_img/'.$list[$i]['letter'].'/'.$letter.'_logo.jpg';                $B->save($data);            }            if($list['big_logo'] != 'Public/default/show.jpg'){                $data['big_logo'] = 'upload/business_img/'.$list[$i]['letter'].'/'.$letter.'.jpg';                $B->save($data);            }        }    }         */     //获取好友足迹        public function zujiList(){                        if(empty($_REQUEST['user_id'])){            $this->ajaxReturn(null,'缺少参数','-1');        }                // business_id 与 user_id                        $map['sq_friend.user_id'] =$_REQUEST['user_id'];                $map['o.status'] =3;//查询已经消费的订单        // $f_map['user_id'] =$_REQUEST['user_id'];                        $F = M('friend')                 ->join(" right join sq_order o on  o.user_id  = sq_friend.f_user_id ")                 ->join(' sq_user u on  u.user_id = sq_friend.f_user_id ')                 ->field(array("u.nick_name as nick_name  ,u.user_id as user_id ,concat(\"".C('WEB_URL')."\",u.user_img) as user_img "))                ->where($map)->select();                        if($F)        $this->ajaxReturn(  $F ,'返回成功','1');        else          $this->ajaxReturn(  $F ,'数据为空','0');                    }//     public function zujiList_bak(){                //         if(empty($_REQUEST['user_id'])){//             $this->ajaxReturn(null,'缺少参数','-1');//         }//         //business_id 与 user_id                        //         $f_map['user_id'] =$_REQUEST['user_id'];                //         //         $f_map['user_id'] =$_REQUEST['user_id'];                        //     	$data =  array();//     	$data['status'] = 1;//     	$data['info'] = '查询成功';//     	$data['data'][0]['coupon_id'] = 1;//     	$data['data'][0]['coupon_name'] = '杰克琼斯';//     	$data['data'][0]['business_id'] = 1;//     	$data['data'][0]['business_name'] = '吴中商厦';//     	$data['data'][0]['address'] = '吴中商厦';//     	$data['data'][0]['use_time'] = '2015 5/20 - 7/31';//     	$data['data'][0]['address'] = '吴中路888号';//     	$data['data'][0]['small_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';//     	$data['data'][0]['desc'] = '欢迎来店使用哦';    //     	$data['data'][1]['coupon_id'] = 1;//     	$data['data'][1]['coupon_name'] = '杰克琼斯';//     	$data['data'][1]['business_id'] = 1;//     	$data['data'][1]['business_name'] = '吴中商厦';//     	$data['data'][1]['address'] = '吴中商厦';//     	$data['data'][1]['use_time'] = '2015 5/20 - 7/31';//     	$data['data'][1]['address'] = '吴中路888号';//     	$data['data'][1]['small_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';//     	$data['data'][1]['desc'] = '欢迎来店使用哦';//     	$this->ajaxReturn($data);//     }        //获取好友足迹    public function zuji(){                //     	$data ="您好，您购买的卡券验证码短信为:" . $code ."！";        //     	$res=$this->send($_REQUEST['phone'],$data);                        $data =  array();        $data['status'] = 1;        $data['info'] = '查询成功';        $data['data'][0]['user_id'] = 1;        $data['data'][0]['user_name'] = '徜徉';        $data['data'][0]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';            $data['data'][1]['user_id'] = 12;        $data['data'][1]['user_name'] = '还开心';        $data['data'][1]['user_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1563418937,2640257337&fm=111&gp=0.jpg';        $data['data'][2]['user_id'] = 12;        $data['data'][2]['user_name'] = '大风歌';        $data['data'][2]['user_img'] = 'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1158549394,2821559545&fm=111&gp=0.jpg';            $this->ajaxReturn($data);    }        //获取卡券信息 卡券明细    public function couponInfo(){    	if(empty($_REQUEST['coupon_id'])){    	    $this->ajaxReturn(null,'缺少参数','-1');    	}//     	$info = M('coupon')->find($_REQUEST['coupon_id']);    	    	if($_REQUEST['user_id']){    	    	    $user_id=$_REQUEST['user_id'];    	    	         	    $map['coupon_id'] = $_REQUEST['coupon_id'];    	    	    	        	    //	1.商家   2.卡券    	    //$map['_string'] = "  k.user_id IS NULL or ( k.user_id=".$user_id."  ) ";    	    	    //     	    sq_coupon_type t on   sq_coupon.business_id=t.business_i    	    	         	        	    $info = M('coupon')    	        	    ->join(" sq_coupon_type t on   sq_coupon.business_id=t.business_id ")    	        	    ->join (' sq_business b on   sq_coupon.business_id=b.business_id ')    	    	    	    //     	    ->join(' sq_keep k on k.x_id=sq_coupon.coupon_id ')    	    // IF(k.user_id=".$user_id.",IF(k.type=2,'1','0'),'0') as is_keep ,    	    ->field(" if(b.lng,b.lng ,0) as lng, if(b.lat,b.lat ,0) as lat, sq_coupon.*,t.c_type,t.c_count,t.start_time,t.end_time,t.mark")->where($map)->find();    	    	    	    //新增足迹    	        	    $map_f['sq_friend.user_id'] =$_REQUEST['user_id'];    	        	    $map_f['o.business_id'] =$info['business_id'];    	    //           1.未支付  2.已支付未消费   3.已消费  4.已过期    	    $map_f['o.status'] =3;    	        	    //            之前的阿飞测试数据 已经去掉    	        	    $F = M('friend')    	         	    ->join("right join  sq_order o on  o.user_id  = sq_friend.f_user_id ")    	         	    ->join(' sq_user u on  u.user_id = sq_friend.f_user_id ')    	         	    ->field(array("u.nick_name as nick_name  ,u.user_id as user_id ,concat(\"".C('WEB_URL')."\",u.user_img) as user_img "))    	        	    ->where($map_f)->select();    	        	    if($F){    	        	        $info['zuji'] = $F;    	    }    	        	        	        	        	    //便利是否收藏        	           	    $data['user_id'] = $_REQUEST['user_id'];    	    $data['x_id'] =$info['coupon_id'];    	    //                         $data['type'] = 1;    	        	        $res = M('keep')->where($data)->find();    	             	             	        if($res){    	                 	            $info['is_keep'] =1 ;    	                 	                 	        }    	             	        else{    	                 	            $info['is_keep'] =0 ;    	                 	        }    	             	    	         	        	        	        	}    	else{    	        	$info = M('coupon')    	    	->join("sq_coupon_type t on   sq_coupon.coupon_type_id = t.c_id")    	    	->field(" 0 as is_keep ,sq_coupon.*,t.c_type,t.c_count,t.start_time,t.end_time,t.mark")->find($_REQUEST['coupon_id']);    	     	    	}    	//    	    	      	        	    	    	//    	$info['small_img'] = C('WEB_URL').$info['small_logo'];    	$info['big_img'] = C('WEB_URL').$info['big_logo'];    	unset($info['big_logo']);    	unset($info['small_logo']);    	$binfo = M('business')->field("address,tel,open_time")->find($info['business_id']);    	$info['address'] = $binfo['address'];    	$info['tel'] = $binfo['tel'];    	$info['open_time'] = $binfo['open_time'];//     	$info['is_confsum']=mt_rand(0,1);    	$info['url'] = C('WEB_URL').'/Home/info/service/id/'.$_REQUEST['coupon_id'];    	    	$info['share_url'] = C('WEB_URL').'/Home/info/service/id/'.$_REQUEST['coupon_id'];    	     	    	$this->ajaxReturn($info,'查询成功',1);    }        //获取抢购券接口 传输经纬度    public function fastCoupon(){    	if(empty($_REQUEST['lng'])||empty($_REQUEST['lat'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	    	$this->ajaxReturn($data,'没有抢购卡券',0);    	    	$data =  array();    	$data['status'] = 1;    	$data['info'] = '查询成功';    	$data['coupon_id'] = 1;    	$data['coupon_name'] = '杰克琼斯';    	$data['old_price'] = '1080';    	$data['new_price'] = '888';    	$data['business_id'] = 1;    	$data['business_name'] = '吴中商厦';    	$data['address'] = '吴中路324号';    	$data['tel'] = '021-34878888';    	$data['use_time'] = '2015 5/20 - 7/31';    	$data['open_time'] = '周一至周日 9:30-22:00';    	$data['address'] = '吴中路888号';    	$data['small_img'] = 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=171654868,2541281644&fm=116&gp=0.jpg';    	$data['big_img'] = 'http://365jia.cn/uploads/news/users/images/zfkdlhgoirehg/image/IMG_7433.gif';    	$data['is_keep'] = 1;    	$data['is_yy'] = 1;    	$data['desc'] = '欢迎来店使用哦';    	$this->ajaxReturn($data,'查询成功',1);    }        //获取通讯录    public function contacts(){        //         $dataList[] = array('user_name'=>'thinkphp','realname'=>'thinkphp@gamil.com');//         $dataList[] = array('user_name'=>'onethink','realname'=>'onethink@gamil.com');//         $User->addAll($dataList);                    	if(empty($_REQUEST['phones'])||empty($_REQUEST['user_id'])){    		$this->ajaxReturn(null,'缺少参数','-1');    	}    	     	//     	$phones =urldecode($_REQUEST['phones']);    	    	    	    	$phones =$_REQUEST['phones'];    	     	    	//手机号,用户名;手机号,用户名;   用;拼接字符串    	$people = explode(';',$phones);    	    	    	    	//     	print_r($people);    	//     	exit;    	    	$U = M("user");      	    	for ($j=0;$j<count($people);$j++){    	           	        	    $fild = explode(',',$people[$j]);    	         	        	    if(empty($fild[0]))    	    continue;    	        	    //     	    for ($i=0;$i<count($fild);$i++){    	            	      $map['user_name']=$fild[0];    	       	           	        //     	    }    	        	    $res_u = $U->where($map)->getField("user_id");    	        	         	    if ($res_u) {    	        	        //update    	            	        $map['realname']=$fild[1];    	            	        $U ->where("user_id=$res_u")->save($map);    	            	        unset($map['realname']) 	;    	            	    }    	    else{  //新增    	            	        $map['status']=0;    	            	        $map['realname']=$fild[1];    	            	     	            	            	            	        //正则手机号 某些人用户习惯手机号前边加区号！！！ 加区号啊！！ 想法去掉！！！    	        $res_u=$U->add($map);    	            	       unset($map['status']) 	;    	           	       unset($map['realname']) 	;    	        //add    	        	    	       //user_id add 好友关系表    	            	           	          	    }    	        	        	    $f_map['user_id'] =$_REQUEST['user_id'];    	         	    $f_map['f_user_id']=$res_u;    	    	    	        	    $F_data = M("friend");    	        	    $F_ret= $F_data->where($f_map)->getField("f_id");    	        	    if(!$F_ret){    	             	        $F_data->add($f_map);    	             	             	    }    	        	}    	       	    	$this->ajaxReturn(null,'成功',1);    }        //获取商圈服务列表    public function serviceList(){                        $page = empty($_REQUEST['page_num']) ? 1 : $_REQUEST['page_num'];        $num = empty($_REQUEST['page_line']) ? 10 : $_REQUEST['page_line'];        //$map['sq_comment.business_id'] = $_REQUEST['business_id'];                        $type_id = empty($_REQUEST['type']) ? 1 : $_REQUEST['type'];            	$model = M("service");    	$list = $model    	->join(' sq_business b on b.business_id=sq_service.business_id ')    	     	->field("if(b.lng,b.lng ,0) as lng, if(b.lat,b.lat ,0) as lat, sq_service.service_id,sq_service.service_name,sq_service.address,sq_service.img,sq_service.type_name,sq_service.service_date,sq_service.tel,is_show,link")->where("type_id=$type_id")->limit(($page-1)*$num, $num)->select();    	$slist = array();    	for($i=0;$i<count($list);$i++){    	    $val['service_id'] = $list[$i]['service_id'];    	    $val['service_name'] = $list[$i]['service_name'];    	    $val['type_name'] = $list[$i]['type_name'];    	    $val['img'] = C('WEB_URL').$list[$i]['img'];    	    $val['service_date'] = $list[$i]['service_date'];    	    $val['tel'] = $list[$i]['tel'];    	    $val['address'] = $list[$i]['address'];    	    $val['is_show'] = $list[$i]['is_show'];    	    $val['lng'] = $list[$i]['lng']? $list[$i]['lng']:0;    	    $val['lat'] = $list[$i]['lat']?$list[$i]['lat']:0;    	        	        	    $price_map['service_id']= $val['service_id'];    	        	    	    	    $model_t = M("coupon");//     	    $price_map['new_price']=     	    $price_list = $model_t->field("old_price,new_price")->where($price_map)->order(" new_price ") ->find();    	        	    $val['old_price'] = $price_list['old_price'];    	        	        	    $val['new_price'] = $price_list['new_price'];    	        	        	    if($list[$i]['is_show']){    	        $val['url'] = $list[$i]['link'];    	    }else{    	        $val['url'] = C('WEB_URL').'/Home/info/service/id/'.$list[$i]['service_id'];    	    }    	        	    $slist[] = $val;    	}    	if($slist)    	$this->ajaxReturn($slist,'成功',1);    	else     	 $this->ajaxReturn(null,'没有数据',0);    	    	    }        //获取抢购券接口    public function banner(){        $list = M("banner")->select();        for ($i=0;$i<count($list);$i++){            $list[$i]['url'] = C('WEB_URL').$list[$i]['url'];        }        $this->ajaxReturn($list,'成功',1);    }        //注册,忘记密码 发送验证码    public function sendcode(){        if(empty($_REQUEST['phone']) || empty($_REQUEST['type'])){            $this->ajaxReturn(null,'缺少参数','-1');        }        $code = rand(1000,9999);                $data ="您好，您的验证码短信为:" . $code ."，请在3分钟内完成注册！";                $this->send($_REQUEST['phone'],$data);                $S = M("sms");        $sms['type'] = $_REQUEST['type'];        $sms['time'] = time();        $sms['isused'] = 0;        $sms['to_phone'] = $_REQUEST['phone'];        $sms['desc'] = $code;        $res = $S->add($sms);                $this->ajaxReturn($sms, "数据成功", 1);                    }    /*     *     public function short(){        $phone = $_REQUEST['phone'];        if($phone == '' || !preg_match("/1[34578]{1}\d{9}$/",$phone)){            $info = '请输入正确的手机号码！';            $this->json(1008,$data,$info);        }        $phone = $phone;        $code = rand(100000,999999);        $_SESSION['phone_code'] = $code;        $data ="您好！您的验证码是：" . $code ;        $post_data = array();        $post_data['account'] = "chuang123";        $post_data['pswd'] = "Tch123456";        $post_data['mobile'] =$phone;        $post_data['msg']=mb_convert_encoding("$data",'UTF-8', 'auto');        $url='http://222.73.117.158/msg/HttpBatchSendSM?';        $o="";        foreach ($post_data as $k=>$v)        {            $o.= "$k=".urlencode($v)."&";        }        $post_data=substr($o,0,-1);        $result = $this->is_post($url,$post_data);        $post = substr($result,15,1);    }        private function is_post($url,$data){            $ch = curl_init ();        curl_setopt ( $ch, CURLOPT_URL, $url);        curl_setopt ( $ch, CURLOPT_POST, 1 );        curl_setopt ( $ch, CURLOPT_HEADER, 0 );        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );        $return = curl_exec ( $ch );        curl_close ( $ch );        return $return;    }         */        public  function  sendtest(){                        $mobile = $_REQUEST['mobile'];                $content =$_REQUEST['content'];               $this->send($mobile,$content);                    }        private function send($mobile,$content){                                        /*--------------------------------         功能:		上海助通短信PHP HTTP接口 发送短信         auther   henry         说明:		发送传递的参数         http://www.ztsms.cn:8800/sendXSms.do?username=用户名&password=密码&mobile=手机号码&content=内容&dstime=&productid=产品ID&xh=留空         --------------------------------*/        $username = 'shjs';		//用户账号        $password = 'r2zR064g';		//密码//         $mobile	 = '13916888888';	//号码//         $content = '测试PHP HTTP接口';		//内容        $content=iconv("UTF-8", "UTF-8", $content);        $dstime = '';		//为空代表立即发送  如果加了时间代表定时发送  精确到秒        $productid =  95533;		//内容        $xh = '';		//留空                $url="http://www.ztsms.cn:8800/sendXSms.do?username=$username&password=$password&mobile=$mobile&content=$content&dstime=&productid=$productid&xh=";       //        echo  $url;                $this->Get($url);           //         if(function_exists('file_get_contents'))//         {//             $file_contents = file_get_contents($url);//         }//         else//         {//             $ch = curl_init();//             $timeout = 5;//             curl_setopt ($ch, CURLOPT_URL, $url);//             curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//             curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//             $file_contents = curl_exec($ch);//             curl_close($ch);//         }//         return $file_contents;                    }       public   function Get($url)    {        if(function_exists('file_get_contents'))        {            $file_contents = file_get_contents($url);        }        else        {            $ch = curl_init();            $timeout = 5;            curl_setopt ($ch, CURLOPT_URL, $url);            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);            $file_contents = curl_exec($ch);            curl_close($ch);        }        return $file_contents;    }            //发送短信        //     private function send($phone,$data){//         //1.生成随机数              //          //2.发送短信//         $post_data = array();//         $post_data['account'] = iconv('GB2312', 'GB2312',"jiekou-clcs-02");//         $post_data['pswd'] = iconv('GB2312', 'GB2312',"Txb159357");//         $post_data['mobile'] = $phone;//         $post_data['msg']=mb_convert_encoding("$data",'UTF-8', 'auto');//         $url='http://222.73.117.158/msg/HttpBatchSendSM?'; //         $o="";//         foreach ($post_data as $k=>$v){//            $o.= "$k=".urlencode($v)."&";//         }        //         $post_data=substr($o,0,-1);         //         $ch = curl_init();//         curl_setopt($ch, CURLOPT_POST, 1);//         curl_setopt($ch, CURLOPT_HEADER, false);//         curl_setopt($ch, CURLOPT_URL,$url);//         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);                 //          return curl_exec($ch);         //          //return//     }    //     public function wx_pay_nofify(){    // //         foreach ($_GET as $key=>$value)// //         {// //             $this->logger("Key: $key; Value: $value");// //         }//         $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];               // //         $postStr ="<xml><appid><![CDATA[wxc2b2e8e97e0962e5]]></appid>// // <bank_type><![CDATA[ABC_DEBIT]]></bank_type>// // <cash_fee><![CDATA[1]]></cash_fee>// // <device_info><![CDATA[APP-001]]></device_info>// // <fee_type><![CDATA[CNY]]></fee_type>// // <is_subscribe><![CDATA[N]]></is_subscribe>// // <mch_id><![CDATA[1265936901]]></mch_id>// // <nonce_str><![CDATA[1402604810]]></nonce_str>// // <openid><![CDATA[o70NMtzyryRGFzeLrZ20Ijg9ts00]]></openid>// // <out_trade_no><![CDATA[1442131436]]></out_trade_no>// // <result_code><![CDATA[SUCCESS]]></result_code>// // <return_code><![CDATA[SUCCESS]]></return_code>// // <sign><![CDATA[E99D84C587012D1D17FEC9F828F46050]]></sign>// // <time_end><![CDATA[20150913160408]]></time_end>// // <total_fee>1</total_fee>// // <trade_type><![CDATA[APP]]></trade_type>// // <transaction_id><![CDATA[1001990400201509130868773941]]></transaction_id>// // </xml>";// //         $this->logger($postStr);         // //         if (isset($_REQUEST)){                        // //             echo "SUCCESS";// //         }        // //         header("Content-Type: text/html; charset=UTF-8");// //         $xmldata = simplexml_load_file ( $parseXmlsUrl, 'SimpleXMLElement', LIBXML_NOCDATA );        //         $xmldata =(array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);// //         $order_id= $xmldata['out_trade_no'];        // //         echo  "$order_id";                //         $map['order_id']= $xmldata['out_trade_no'];                //        ////         $map['status'] = '1';                 //         $Model = M("order");        //         ////         $list=$Model ->where($map)->find();        //         if($list){            //            unset($map['status'] );           //             $data['status'] = '2';//             $res = $Model ->where($map)->save($data);//         }        //         if($res){                        //             $this->logger("SUCCESS:".  $map['order_id']);                        // //             echo "SUCCESS";            //         }            //         else{//             //是否记录日志            //             $this->logger("Fail:".  $map['order_id']);//         }        //         echo "SUCCESS";//         //日志记录         //     }    public function wx_pay_notify(){    //         foreach ($_GET as $key=>$value)        //         {        //             $this->logger("Key: $key; Value: $value");        //         }    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];         //         $postStr ="<xml><appid><![CDATA[wxc2b2e8e97e0962e5]]></appid>    // <bank_type><![CDATA[ABC_DEBIT]]></bank_type>    // <cash_fee><![CDATA[1]]></cash_fee>    // <device_info><![CDATA[APP-001]]></device_info>    // <fee_type><![CDATA[CNY]]></fee_type>    // <is_subscribe><![CDATA[N]]></is_subscribe>    // <mch_id><![CDATA[1265936901]]></mch_id>    // <nonce_str><![CDATA[1402604810]]></nonce_str>    // <openid><![CDATA[o70NMtzyryRGFzeLrZ20Ijg9ts00]]></openid>    // <out_trade_no><![CDATA[1442131436]]></out_trade_no>    // <result_code><![CDATA[SUCCESS]]></result_code>    // <return_code><![CDATA[SUCCESS]]></return_code>    // <sign><![CDATA[E99D84C587012D1D17FEC9F828F46050]]></sign>    // <time_end><![CDATA[20150913160408]]></time_end>    // <total_fee>1</total_fee>    // <trade_type><![CDATA[APP]]></trade_type>    // <transaction_id><![CDATA[1001990400201509130868773941]]></transaction_id>    // </xml>";    //         $this->logger($postStr);         //         if (isset($_REQUEST)){    //             echo "SUCCESS";    //         }    //         header("Content-Type: text/html; charset=UTF-8");    //         $xmldata = simplexml_load_file ( $parseXmlsUrl, 'SimpleXMLElement', LIBXML_NOCDATA );    $xmldata =(array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);                $rechar_id= $xmldata['attach'];            $openid= $xmldata['openid'];            $money=$xmldata['total_fee']*10;               //         echo  "$order_id";           //                     $this->logger("SUCCESS:3=". $list2['balance']);//     $map['order_id']= $xmldata['out_trade_no'];//     ////     $map['status'] = '1';         $Model = M("rechar");//     //    $list=$Model ->where("id=$rechar_id")->find();       if($list){                           $data['status'] = '1';        $res = $Model ->where("id=$rechar_id")->save($data);               $sql=M("rechar")->getLastSql();//         $te="openid=$openid";            }    $openid='"'."$openid".'"';    $balance=M('user')->field('balance')->where("openid=$openid")->find();    // dump($balance);exit;        $balance['balance']=$money+$balance['balance'];        $table=M('user')->where("openid=$openid")->save($balance);    $sql1=M("user")->getLastSql();    if($res&& $table){              $this->logger("SUCCESS:".  $rechar_id);                        echo "<xml>                  <return_code><![CDATA[SUCCESS]]></return_code>                  <return_msg><![CDATA[OK]]></return_msg>                </xml>";//                     return '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';          }    else{        //是否记录日志        $this->logger("Fail:".  $rechar_id."Sql:".$sql."sql1:".$sql1);    }    //     if ($res) {//         $str='<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';//     }else{//         $str='<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[签名失败]]></return_msg></xml>';//     }    echo "<xml>                  <return_code><![CDATA[SUCCESS]]></return_code>                  <return_msg><![CDATA[OK]]></return_msg>                </xml>";    //日志记录//     return $res;     }        function logger($log_content)    {            $max_size = 100000;        $log_filename = "log.xml";        if(file_exists($log_filename) and (abs(filesize($log_filename)) > $max_size)){unlink($log_filename);}        file_put_contents("upload/".$log_filename, date('H:i:s')." ".$log_content."\r\n", FILE_APPEND);    }       function recommend()    {            $userinfo=M('user');        $data[invite]=0;        $invite=$userinfo->save($data);    }    }?>